/*
 * api config
 * @Author: shuo
 * @Date: 2018-07-18 15:16:36
 * @Last Modified by: elvis.lam
 * @Last Modified time: 2018-12-06 14:44:03
 */

import config from './../config'

// 去掉配置域名地址尾部多余"/"
const replaceHostUrl = url => url.replace(/\/+$/, '')

/*
 * 不同环境的业务请求域名配置，通过ext.json获取域名配置，例如：
 * apiConfig.host            https://ztxcx.yunlai.cn
 * apiConfig.mpHost          https://mp.yunlai.cn
 * apiConfig.cpHost          https://cp.yunlai.cn
 * apiConfig.payHost         https://payapi.yunlai.cn
 * apiConfig.emallHost       https://emallapi.yunlai.cn
 * apiConfig.suitCouponHost  https://tqhd.yunlai.cn
 */
const extConfig = wx.getExtConfigSync()
const apiConfig = {
  host: replaceHostUrl(extConfig[`host`] || config[`API_HOST`]),
  mpHost: replaceHostUrl(extConfig[`mpHost`] || config[`MP_HOST`]),
  cpHost: replaceHostUrl(extConfig[`cpHost`] || config[`CP_HOST`]),
  payHost: replaceHostUrl(extConfig[`payHost`] || config[`PAY_HOST`]),
  emallHost: replaceHostUrl(extConfig[`emallHost`] || config[`EMALL_HOST`]),
  suitCouponHost: replaceHostUrl(extConfig[`suitCouponHost`] || config[`SUIT_COUPON_HOST`])
}

// 获取首页
export const getIndexPage = `${apiConfig.host}/special/client/getIndexPage`
// 专题列表
export const specialClientList = `${apiConfig.host}/special/client/list`
// 专题详情
export const specialDetail = `${apiConfig.host}/special/client/detail`
// 专题统计
export const specialLikeCount = `${apiConfig.host}/special/client/getLikeCount`
// 专题点赞列表
export const specialLastRank = `${apiConfig.host}/special/client/getLastRank`
// 专题增加点赞
export const specialAddLike = `${apiConfig.host}/special/client/addLike`
// 专题取消点赞
export const specialCancelLike = `${apiConfig.host}/special/client/cancelLike`
// 专题点赞状态
export const specialCheckLike = `${apiConfig.host}/special/client/checkLike`
// 立减优惠标题
export const discountRuleContent = `${apiConfig.emallHost}/emall/discountrule/getDiscountRuleContent`
// 商品列表
export const goodsList = `${apiConfig.emallHost}/item/list`
// 商品基本信息
export const goodsBaseInfo = (id) => `${apiConfig.emallHost}/item/${id}/basics`
// 商品 SKU 信息
export const goodsSkuInfo = (id) => `${apiConfig.emallHost}/item/${id}/sku`
// 商品添加购物袋
export const cardItemAdd = `${apiConfig.host}/special/cart/item/add`
// 商品购物袋总数
export const cardItemCount = `${apiConfig.host}/special/cart/item/count`
// 商品详情
export const goodsFullDetails = (id) => `${apiConfig.emallHost}/item/${id}/fullDescription`
// 商品优惠信息
export const goodsDiscountInfo = `${apiConfig.emallHost}/emall/discountrule/getDiscountRuleByGoodsId`
// 发起授权
export const platformSubmitAuth = `${apiConfig.mpHost}/cjds-auth/platformUserAuth/submitAuth`
// 获取用户信息
export const accountInfo = `${apiConfig.mpHost}/cjds-auth/platformUserAuth/getAccountKeyInfo`
// 检验会话是否有效
export const checkSession = `${apiConfig.mpHost}/cjds-auth/platformUserAuth/checkSession`
// 解析手机号码
export const parsePhone = `${apiConfig.mpHost}/miniProgram/function/parsePhone`
// 物流基础信息
export const deliveryBasic = `${apiConfig.emallHost}/oms/order_relate/deliveryBasic`
// 物流详情
export const deliveryDetail = `${apiConfig.emallHost}/emall/common/logistics/trace`
// 订单交易信息
export const orderTradeInfo = `${apiConfig.emallHost}/oms/order_main/getOrderTrade`
// 订单明细
export const orderDetail = `${apiConfig.emallHost}/oms/order_main/getOrderItemsDetail`
// 订单删除
export const orderDelete = `${apiConfig.emallHost}/oms/order_main/delete`
// 确认收货
export const confirmReceived = `${apiConfig.emallHost}/oms/order_main/confirmReceived`
// 订单取消
export const orderCancel = `${apiConfig.emallHost}/oms/order_main/cancel`
// 再次购买
export const buyAgain = `${apiConfig.emallHost}/oms/order_main/againBuy`
// 获取商家和用户信息
export const enterpriseAndUserInfo = `${apiConfig.host}/special/client/getEntInfoAndUserInfo`
// 获取用户微信会员卡信息
export const getUserCardInfo = `${apiConfig.mpHost}/miniProgram/function/getUserCardInfo`
// 订单列表
export const orderList = `${apiConfig.emallHost}/oms/order_main/getOrderList`
// 订单号获取支付信息
export const applyPay = `${apiConfig.emallHost}/emall/pay/applyPayOrder`
// 购物袋列表
export const shoppingCartList = `${apiConfig.host}/special/cart/item/list`
// 勾选/反选购物袋
export const shoppingCartCheck = `${apiConfig.host}/special/cart/item/check`
// 添加购物袋
export const shoppingCartAdd = `${apiConfig.host}/special/cart/item/add`
// 更新购物
export const shoppingCartUpdate = `${apiConfig.host}/special/cart/item/update`
// 删除购物袋
export const shoppingCartRemove = `${apiConfig.host}/special/cart/item/delete`
// 购物袋总数量
export const shoppingCartCount = `${apiConfig.host}/special/cart/item/count`
// 会员卡开卡信息
export const memberRegisterInfo = `${apiConfig.mpHost}/miniProgram/function/getActivateComponentUrl`
// 激活会员卡
export const vipCardActive = `${apiConfig.mpHost}/vipCard/activateFromMiniProgram`
// 默认收货地址
export const defaultAddress = `${apiConfig.emallHost}/emall/address/getDefault`
// 微信地址转换接口
export const convertWeixinAddress = `${apiConfig.emallHost}/emall/address/convertWeixinAddress`
// 地址转经纬度
export const geoLocation = `${apiConfig.emallHost}/emall/common/geocode/geo`
// 查询附近门店
export const nearStore = `${apiConfig.host}/special/order/getNearStore`
// 下单可用/不可用优惠券列表
export const orderConponList = `${apiConfig.emallHost}/emall/coupon/listAllCouponsForOrder`
// 订单确认
export const confirmOrder = `${apiConfig.emallHost}/oms/order_main/confirm`
// 订单重复校验
export const checkRepeatOrder = `${apiConfig.emallHost}/oms/order_main/getNoPayBuyScene`
// 订单创建
export const createOrder = `${apiConfig.host}/special/order/create`
// 获取支付交易信息
export const payInfo = `${apiConfig.payHost}/payment/client/trade/queryForPay`
// 获取支付统一入口信息（包括微信支付签名）
export const unifiedPay = `${apiConfig.payHost}/payment/client/unifiedPay`
// 搜集表单信息
export const presentFormTemplate = `${apiConfig.host}/special/wechat/presentFormTemplate`
// 会员卡等级权益
export const memberWelfare = `${apiConfig.host}/special/wechat/queryWelfareName`
// 检查企业是否开通微信会员卡
export const checkWeChatCardState = `${apiConfig.host}/special/wechat/checkWeChatCard`
// 等级权益明细（升级礼券明细）
export const welfareGiftInfo = `${apiConfig.host}/special/coupon/getGiftInfo`
// 查询地址列表
export const addressList = `${apiConfig.emallHost}/emall/address/queryList`
// 设置默认地址
export const setDefaultAddress = `${apiConfig.emallHost}/emall/address/setDefault`
// 删除地址
export const deleteAddress = `${apiConfig.emallHost}/emall/address/delete`
// 保存地址
export const saveAddress = `${apiConfig.emallHost}/emall/address/save`
// 查询地址数据
export const queryAddressData = `${apiConfig.host}/special/address/queryAddressData`
// 验证码查询导购信息
export const getGuideInfo = `${apiConfig.mpHost}/sharedPerformance/sharedOp/getGuideInfo`
// 注册分享业务员
export const registerShare = `${apiConfig.mpHost}/sharedPerformance/sharedOp/register`
// 发送手机号验证码
export const sendVerifyCode = `${apiConfig.mpHost}/sharedPerformance/sharedOp/sendVerifyCode`
// 查询分享业务员记录
export const getInfo = `${apiConfig.mpHost}/sharedPerformance/sharedOp/getInfo`
// 上报分享访问记录
export const accessSharedData = `${apiConfig.mpHost}/sharedPerformance/sharedChain/access`
// 生成分享关系链id
export const createSharedChainCode = `${apiConfig.mpHost}/sharedPerformance/sharedChain/create`
// 上报分享业绩
export const addSharedBizData = `${apiConfig.mpHost}/sharedPerformance/add`
// 订单积分收益
export const orderProfitPoint = `${apiConfig.emallHost}/oms/order_relate/orderProfitPoint`
// 订单锁
export const orderLock = `${apiConfig.emallHost}/oms/order_relate/paid_callback_lock`
// 分享功能开关状态
export const switchStatus = `${apiConfig.mpHost}/sharedPerformance/config/getStatus`
// 获取上架LOGO
export const enterLogo = `${apiConfig.host}/special/client/getEnterLogo`
// 获取专题数量
export const specialCount = `${apiConfig.host}/special/client/getTotalNum`
// 注册开卡
export const regVip = `${apiConfig.host}/special/client/regVip`
// 获取开卡验证码
export const clientSendVerifyCode = `${apiConfig.host}/special/client/sendVerifyCode`
// 生成场景值二维码
export const createSceneQrcode = `${apiConfig.host}/special/client/createSceneQrcode`
// 邀请二维码场景值解析
export const parseScene = `${apiConfig.host}/special/shared/parseScene`
// 获取个人卡券列表
export const couponsList = `${apiConfig.mpHost}/wechat4fw/coupons/list`
// 转赠卡券相关信息
export const couponPresentInfo = `${apiConfig.host}/special/coupon/getCouponPresentInfo`
// 直接发券活动基础信息
export const couponActivityInfo = `${apiConfig.host}/special/coupon/getCouponActivityInfo`
// 直接发券活动验证-当前是否可以领取
export const checkDrawStatus = `${apiConfig.host}/special/coupon/checkDrawStatus`
// 用户卡券详情
export const couponsDetail = `${apiConfig.mpHost}/wechat4fw/coupons/userDetail`
// 卡券领取
export const couponsReceive = `${apiConfig.mpHost}/wechat4fw/coupons/receive`
// 领取转赠卡券
export const couponsPresent = `${apiConfig.mpHost}//wechat4fw/coupons/receivePresentCoupon`
// 获取某个卡券适用门店
export const matchedStoreList = `${apiConfig.mpHost}/wechat4fw/coupons/matchedStoreList`
// 获取附近城市门店
export const queryNearCityStores = `${apiConfig.mpHost}/wechat4fw/getNearCityShopList`
// 直接发券-批量查询卡券
export const couponActivityList = `${apiConfig.host}/special/client/activity/queryCouponActivityList`
// 直接发券-批量检测卡券领取次数
export const couponActivityJoinNum = `${apiConfig.host}/special/client/activity/getJoinNum`
// 套券活动详细
export const getIndexPageJson = `${apiConfig.suitCouponHost}/marketing/groupCoupon/getIndexPageJson`
// 套券领取次数
export const getResidueNum = `${apiConfig.suitCouponHost}/marketing/groupCoupon/getResidueNumVersion2`
// 套券领取卡券
export const getPrize = `${apiConfig.suitCouponHost}/marketing/groupCoupon/prize`
// 获取当前时间
export const getCurrentTime = `${apiConfig.suitCouponHost}/marketing/groupCoupon/getCurrentTime`
// 创建已授权会话信息
export const createSession = `${apiConfig.mpHost}/cjds-auth/platformUserAuth/createSession`
// 核销页面
export const verifycoupon = `${apiConfig.cpHost}/guide/personal/verifycoupon`
// 场景电商-接口-服务号-卡券-活动领取页面（包含转增功能）
export const couponsDraw = `${apiConfig.mpHost}/wechat4fw/coupons/draw`